package com.example.petplatform.controller;

import com.example.petplatform.common.Result;
import com.example.petplatform.entity.petSurrender;
import com.example.petplatform.entity.Param.Params;
import com.example.petplatform.service.petSurrenderService;
import com.github.pagehelper.PageInfo;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 宠物送养管理接口
 */
@RestController
@RequestMapping("/petSurrender")
public class petSurrenderController {
    @Resource
    private petSurrenderService petSurrenderService;

    // 获取所有宠物送养信息
    @GetMapping("/all")
    public Result getAllSurrenders() {
        List<petSurrender> list = petSurrenderService.getAllSurrenders();
        return Result.success(list);
    }

    // 分页查询宠物送养信息
    @GetMapping("/search") 
    public Result surrenderSearch(Params params) {
        PageInfo<petSurrender> list = petSurrenderService.surrenderSearch(params);
        return Result.success(list);
    }

    // 添加或修改宠物送养信息
    @PostMapping("/add")
    public Result surrenderAdd(@RequestBody petSurrender surrender) {
        if(surrender.getId() == null) {
            // 添加数据
            List<petSurrender> list = petSurrenderService.surrenderAdd(surrender);
            return Result.success(list);
        } else {
            // 修改数据
            List<petSurrender> list = petSurrenderService.surrenderUpdate(surrender);
            return Result.success(list);
        }
    }

    // 删除宠物送养信息
    @DeleteMapping("/delete")
    public Result surrenderDelete(@RequestBody petSurrender surrender) {
        List<petSurrender> list = petSurrenderService.surrenderDelete(surrender.getId());
        return Result.success(list);
    }
}
